//    Copyright (C) Kherty.  All rights reserved.
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Windows.Data;

namespace OpenLS.Spreadsheet.UI.Internals
{
    class StyleFinderConverter : IMultiValueConverter
    {
        public object Convert(object[]  value, Type targetType, object parameter, CultureInfo culture)
        {
            Range range =  value[0] as Range;
            IEnumerable<CellStyle> styles = (IEnumerable<CellStyle>)value[1];

            if (range == null)
                return null;
            CellStyle result = null;
            bool first = true;
            foreach (var cell in range.GetNonEmptyCells())
            {
                if (first)
                {
                    first = false;
                  throw new NotImplementedException("CELLSTYLE"); //\\ result = Enumerable.FirstOrDefault(styles, ss => ss.Record == cell.StyleRecord);
                }
                else
                {
                    if (result == null)
                    {
                        if (cell.FormattingRecord != null)
                            return null;
                    }
                    else
                    {

                        throw new NotImplementedException("CELLSTYLE"); //\\ if (cell.StyleRecord != result.Record)
                            return null;
                    }
                }
            }
            return result;

        }

        public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture)
        {
            throw new System.NotSupportedException();
        }

    }
}